class TransferCardAdapter(private val context: Context) : CardScrollAdapter() {
    private val transfers = mutableListOf<TransferInfo>()

    override fun getCount(): Int = transfers.size

    override fun getItem(position: Int): Any = transfers[position]

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val transfer = transfers[position]
        
        return LayoutInflater.from(context).inflate(R.layout.transfer_card, parent, false).apply {
            findViewById<TextView>(R.id.fileName).text = transfer.fileName
            findViewById<ProgressBar>(R.id.progressBar).apply {
                progress = ((transfer.transferredSize.toFloat() / transfer.fileSize) * 100).toInt()
            }
            findViewById<TextView>(R.id.transferSpeed).text = 
                "${formatSpeed(transfer.speed)}/s"
        }
    }

    private fun formatSpeed(bytesPerSecond: Long): String {
        return when {
            bytesPerSecond < 1024 -> "$bytesPerSecond B"
            bytesPerSecond < 1024 * 1024 -> "${bytesPerSecond / 1024} KB"
            else -> "${bytesPerSecond / (1024 * 1024)} MB"
        }
    }
} 